home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archivers / XpkDisk / name.c < prev    next >
C/C++ Source or Header  |  1996-09-26  |  2KB  |  92 lines

  1. /*-
  2.  * NAME.C
  3.  *
  4.  * The knowledge of the file names used for tracks.
  5.  *
  6.  * $Id: name.c,v 1.3 1995/04/08 20:23:48 Rhialto Exp $
  7.  * $Log: name.c,v $
  8.  * Revision 1.3  1995/04/08  20:23:48  Rhialto
  9.  * Add/correct version strings.
  10.  *
  11.  * Revision 1.2  1993/11/08  13:18:19  Rhialto
  12.  * Add RCS tags.
  13.  *
  14.  *
  15.  * This code is (C) Copyright 1993 by Olaf Seibert. All rights reserved.
  16.  * May not be used or copied without a licence.
  17. -*/
  18. #include "xpkdisk.h"
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <ctype.h>
  22.  
  23. extern struct DosLibrary   *DOSBase;
  24.  
  25. static const char rcsId[] = "$Id: name.c,v 1.3 1995/04/08 20:23:48 Rhialto Exp $";
  26. static const char      Subdir[] = "Group_%04x_%c%c";
  27. static const char      File[]    = "Track_%04x_%c%c";
  28.  
  29. #define HASHTABLESIZE    72    /* Must be less than 13*13 */
  30.  
  31. Prototype int Hash(unsigned char *name);
  32.  
  33. int
  34. Hash(unsigned char *name)
  35. {
  36.     int val, len, i;
  37.  
  38.     val = len = strlen(name);
  39.     for (i=0; i<len; i++)
  40.     val = ((val*13) + (int)toupper(*name++)) & 0x7ff;
  41.  
  42.     return val;
  43. }
  44.  
  45. int
  46. HashName(char *filename, char *pattern, int number, int hash)
  47. {
  48.     int         hh;
  49.     int         len;
  50.  
  51.     len = sprintf(filename, pattern, number, 'M', 'M');
  52.     hh = (Hash(filename) - hash) % HASHTABLESIZE;
  53.     filename[--len] -= hh % 13;
  54.     filename[--len] -= hh / 13;
  55.  
  56.     return len + 2;
  57. }
  58.  
  59. Prototype void NewName(char *filename, int track);
  60.  
  61. void
  62. NewName(char *filename, int track)
  63. {
  64.     int         groupd = track / HASHTABLESIZE;
  65.     int         group = groupd * HASHTABLESIZE;
  66.     int         len;
  67.  
  68.     len = HashName(filename, Subdir, group, groupd % HASHTABLESIZE);
  69.     filename += len;
  70.     *filename++ = '/';
  71.     HashName(filename, File, track, track % HASHTABLESIZE);
  72. }
  73.  
  74. Prototype void MakeSubDirs(int mintrack, int maxtrack);
  75.  
  76. void
  77. MakeSubDirs(int mintrack, int maxtrack)
  78. {
  79.     char        dirname[40];
  80.     BPTR        fl;
  81.     int         g;
  82.     int         gd;
  83.  
  84.     for (gd = mintrack / HASHTABLESIZE, g = gd * HASHTABLESIZE;
  85.      g <= maxtrack;
  86.      gd++, g += HASHTABLESIZE) {
  87.     HashName(dirname, Subdir, g, gd % HASHTABLESIZE);
  88.     if (fl = CreateDir(dirname))
  89.         UnLock(fl);
  90.     }
  91. }
  92.